export function isvalidUsername(str) {
	const valid_map = ['admin', 'editor']
	return valid_map.indexOf(str.trim()) >= 0
}

/* 合法uri*/
export function validateURL(textval) {
	const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
	return urlregex.test(textval)
}

/* 小写字母*/
export function validateLowerCase(str) {
	const reg = /^[a-z]+$/
	return reg.test(str)
}

/* 大写字母*/
export function validateUpperCase(str) {
	const reg = /^[A-Z]+$/
	return reg.test(str)
}

/* 大小写字母*/
export function validatAlphabets(str) {
	const reg = /^[A-Za-z]+$/
	return reg.test(str)
}

/* 表单验证 */
var blur = function (val) {
  if (val) {
	return { required: true, message: val, trigger: 'blur' }
  } {
	return { required: true, message: '必填项不能为空', trigger: 'blur' }
  }
}

var change = function (val) {
  if (val) {
	return { required: true, message: val, trigger: 'change' }
  } {
	return { required: true, message: '必填项不能为空', trigger: 'change' }
  }
}
/*名字长度控制*/
var nameLength = function (min, max, tip) {
  if (tip) {
	return { min: min, max: max, message: tip, trigger: 'blur' }
  }
}

var isSome = function (val1, val2, msg) {
  return new Promise(function (resolve, reject) {
	if (val1 !== val2) {
	  let message = msg ? msg : '前后密码输入不一致'
	  var msg = {
		message: message,
		type: 'error',
		duration: 2000
	  };
	  // resolve(msg)
	} else {
	  reject()
	}
  })
}

var phone = { pattern: /^1[34578]\d{9}$/, message: '请输入正确的11位手机号码', trigger: 'blur' }
var vin = { pattern: /^[A-Na-nR-Zr-z0-9]*$/, message: '请输入正确的Vin码', trigger: 'blur' }
var inputVin = { pattern: /^[A-Z0-9]{17,17}$/, message: '请输入正确的17位车架号（英文或数字）', trigger: 'blur' }
var psd = { pattern:/^[a-zA-Z0-9@&,.+=$^~]{6,16}$/, message: '密码由6-16位字母、数字或@&,.+=$^~组成', trigger: 'blur' } // 密码验证
// var psd = { pattern:/^[a-zA-Z0-9]{6,16}$/, message: '密码由6-16位字母、数字组成' };

var userName = { pattern: /^[A-Za-z0-9]{4,16}$/, message: '请输入4~16位英文或数字或英文数字组合', trigger: 'blur' }
var noSpace = { pattern: /^\S+$/, message: '请勿输入空格', trigger: 'blur' }
var number = { pattern: /^([1-9]\d*|0)(\.\d*[1-9])?$/, message: '请输入非0开头的数字', trigger: 'blur' }
var radiusNumber = { pattern: /^[0-9]*$/, message: '请输入整数', trigger: 'blur' }
var pointNumber = { pattern: /^([1-9][0-9]*)+(.[0-9]{1,10})?$/, message: '请输入数字（小数点后保留10位）', trigger: 'blur' }
var parkName = { pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/, message: '请输入正确停车场名称', trigger: 'blur' }
var license = { pattern: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[警京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{0,1}[A-Z0-9]{4,5}[A-Z0-9挂学警军港澳]{1}$/, message: '请输入正确的车牌号', trigger: 'blur'}
var rfid = { pattern: /^[A-Z0-9]{16}$/, message: '请输入16位正确的RFID编号（英文或数字）', trigger: 'blur' }
var Idcard = { pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx])|([1−9]\d5\d2((0[1−9])|(10|11|12))(([0−2][1−9])|10|20|30|31)\d2[0−9Xx])|([1−9]\d5\d2((0[1−9])|(10|11|12))(([0−2][1−9])|10|20|30|31)\d2[0−9Xx])/, message: '请输入合法的身份证号码', trigger: 'blur' }

export { blur, change, phone, vin, inputVin, psd, isSome, nameLength, userName, noSpace, number, radiusNumber, pointNumber, parkName, license, rfid, Idcard}


